package com.wf.course.web.controller.goods;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.utils.export.GoodsInfoOrderExcelExporter;
import com.utils.export.GoodsOrderExcelExporter;
import com.utils.export.GoodsSalesExcelExporter;
import com.utils.page.PageBean;
import com.wf.course.model.ad.VipCard;
import com.wf.course.model.course.CourseInfo;
import com.wf.course.model.goods.GoodsInfo;
import com.wf.course.model.goods.GoodsOrder;
import com.wf.course.model.goods.GoodsOrderRelation;
import com.wf.course.model.member.CoinLog;
import com.wf.course.model.user.User;
import com.wf.course.model.user.UserRoleRelation;
import com.wf.course.service.ICourseChapterService;
import com.wf.course.service.ICourseInfoService;
import com.wf.course.service.IGoodsInfoService;
import com.wf.course.service.IGoodsOrderRelationService;
import com.wf.course.service.IGoodsOrderService;
import com.wf.course.service.IUserRoleRelationService;
import com.wf.course.service.IVipCardService;
import com.wf.course.web.Interceptor.LogInfo;
/**
 * 订单信息
 * @content 列表Controller
 */
@RequestMapping("goodsActualSale")
@Controller
public class GoodsActualSaleController {

	@Autowired
	private IGoodsOrderService goodsOrderService;
	@Autowired
	private IGoodsOrderRelationService orlService;
	@Autowired
	private ICourseInfoService courseInfoService;
	@Autowired
	private ICourseChapterService chapterService;
	@Autowired
	private IVipCardService cardService;
	@Autowired
	private IGoodsInfoService goodsInfoService;
	
	@Autowired
	private IUserRoleRelationService userRoleRelationService;

	/**
	 * 按商品-课程编号计算销售额：
	 * 1.按类型查询所有商品：
	 * 2.查询订单关系表中支付成功的订单
	 * 3.根据订单编号，查询订单关系表购买的商品（是否是用铜钱）
	 * 未使用：如果订单关系表中是1个商品,取即实际支付总额；多个商品，取商品支付价格
	 * 使用：如果订单关系表中是1个商品，取实际支付总额；多个商品（比较多个商品的价格高低，如果本商品属于高价商品，实际支付总额=支付价格-铜钱数，
	 * 如果本商品属于低价商品，实际支付总额=支付单价）
	 * @param model
	 * @return
	 */
	 @LogInfo("按商品统计销售额")
	@RequestMapping("getGoodsSale")
	public String getGoodsSale(@RequestParam(value = "pageNo", required = false) Integer pageNo,
			@RequestParam(value = "pageSize", required = false) Integer pageSize,
			@RequestParam(value = "userSource", required = false) String userSource, 
			@RequestParam(value = "goodsSort", required = false) String goodsSort, 
			@RequestParam(value = "orderBeginTime", required = false) String orderBeginTime, 
			@RequestParam(value = "orderEndTime", required = false) String orderEndTime, 
			Model model) {
			 
			
			PageBean<GoodsOrderRelation> pageBean = new PageBean<GoodsOrderRelation>(pageNo, pageSize, null, null);
			pageBean.setUrl("goodsOrder/getGoodsSale");
			
			this.orlService.getGoodsSale(pageBean);
			
			model.addAttribute("page", pageBean);
		
			
			return "goods/goodsSaleList";
	}
	 
	 
	}

